﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using HGZP.BLL;
using HGZP.Model;
using HGZP.PLL;
using System.Data;
namespace SZCB.admin.FoodManager
{
    public partial class AddFoodSubClass : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack == false)
            {
                BindFoodClass();
            }
        }

        private void BindFoodClass()
        {
            CsFoodClassBLL myCsFoodClassBLL = new CsFoodClassBLL();
            ddlContentClass.DataSource = myCsFoodClassBLL.F02_SelectHaveWhere("");
            ddlContentClass.DataTextField = myCsFoodClassBLL.sName;
            ddlContentClass.DataValueField = myCsFoodClassBLL.sGuid;
            ddlContentClass.DataBind();
            ListItem listItem = new ListItem();
            listItem.Text = "----请选择分类----";
            listItem.Value = "0";
            ddlContentClass.Items.Add(listItem);
            ddlContentClass.SelectedValue = "0";
        }

        /// <summary>
        /// 提交按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            CFoodSubClassBLL foodbll = new CFoodSubClassBLL();
            DataTable dt = foodbll.F02_SelectHaveWhere("sName = '" + txtName.Text + "'");
            if (dt.Rows.Count > 0)
            {
                string strErrmessage = "该食品子类已添加";
                Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('" + strErrmessage + "');</script>");
                return;
            }
            CFoodSubClass foodclass = new CFoodSubClass();
            foodclass.sGuid = MyFunction.GetNewGuid();
            foodclass.sName = txtName.Text;
            foodclass.dCreateDate = DateTime.Now;
            foodclass.sClassGuid = ddlContentClass.SelectedValue;
            if (!foodbll.F_Insert(foodclass))
            {
                string strErrmessage = "添加食品子类失败";
                Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('" + strErrmessage + "');</script>");
                return;
            }

        }

    }
}